%percentage of converged experiments as a function of time
function plotconv6(dir,m,prefs)
files=[2 2; 2 3; 2 5; 2 10; 3 2; 5 2; 10 2];
iterationsPerBlock = 100;
tstdata=load(strcat(dir,'\m',int2str(m),'_n',int2str(files(1,1)),'_d',int2str(files(1,2)),'_',prefs,'.run.results'));
numfiles = length(files);
num=length(tstdata);
numblocks=tstdata(num,3)+1;
totruns=num/numblocks; % total runs in a single file
col=8;
data=zeros(numblocks,totruns*numfiles);
for i=1:numfiles
    %load a file
    alldata=load(strcat(dir,'\m',int2str(m),'_n',int2str(files(i,1)),'_d',int2str(files(i,2)),'_',prefs,'.run.results'));
    for j=1:totruns
        for k=1:numblocks
            %collect datapoints for each block, but for all runs across
            %files. This appends results of different files into a single
            %matrix.
            data(k,(i-1)*totruns+j)=alldata((j-1)*numblocks+k,col);
        end;
    end;
end;

errors=[0.01 0.001 0.0001];
result=zeros(size(data,1),length(errors));
for e=1:length(errors)
    for i=1:size(data,1) % iterate through the blocks
        for j=1:size(data,2) % iterate through the runs
            if (data(i,j)<=errors(e))
                result(i,e)=result(i,e)+1;
            end;
        end;
    end;
end;
result=result./(totruns*numfiles);




%a1 = x0:(x1-x0)/10:x1;


%for a1=.4
%g=1.5
lw=3;
fs=24;
clf;
set(gca,'FontSize',fs);
set(gca,'XTick',[1000,2000,3000,4000,5000]);
set(gca,'XTickLabel',{'1k','2k','3k','4k','5k'});
colors='ymcrgby';
legendstr=[];
x=(1:numblocks)*iterationsPerBlock;
for i=1:length(errors)
    if (i==1)
        ls=':';
    elseif (i==2)
        ls='-';
    elseif (i==3)
        ls='--';
    elseif (i==4)
        ls='-.';
    end;
    plot(x,result(:,i),'Color','k','LineWidth', lw, 'LineStyle',ls);
    legendstr=strvcat(legendstr,strcat('error=',num2str(errors(i))));
    hold on;
end;
ylim([0 1]);
xlim([0 iterationsPerBlock*numblocks]);
legend(legendstr,'Location','SouthEast');
xlabel('iteration', 'FontSize', fs);
%ylabel('percentage', 'FontSize', fs);
%title('Percentage of all runs that converge to a given error');
hold off;


name = strcat('./conv6_m',int2str(m),'_',prefs);
print('-depsc',strcat(name, '.eps'));
%print('-dpdf',strcat(name, '.pdf'));
end

